#!/usr/bin/env node

const log = console.log;

let timer1, timer2, count = 1;

log('启动定时器timer1!');
timer1 = setInterval(loop1, 500);//setInterval()方法可按照指定的周期来调用函数或计算表达式
setTimeout(()=>{
  log('time1结束！');
  clearInterval(timer1);
  log('启动定时器timer2！');
  timer2 = setInterval(loop2, 500);
},5000);               //延迟 5秒后执行

function loop1(){
  log('正在执行timer1！');
}
function loop2(){
  log('正在执行timer2！');
  if(count++ >= 5){
    log('timer2结束！');
    global.clearInterval(timer2);
  }
}
